﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Ccit.OA.MsNotify;
using System.Collections.Generic;
using Newtonsoft.Json;
using Ccit.OA.Utils;
using Ccit.Utils;
namespace Ccit.OA.Notify
{
    public partial class notify_manage_list : Ccit.Utils.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                ViewState["Query"] = "";
                ViewState["Type"] = "1";
                _hidQuery.Value = (null != Request.QueryString["Query"]) ? Request.QueryString["Query"].ToString() : "";
                if (Session["QryClause"] != null)
                {
                    ViewState["Query"] = Session["QryClause"];
                    Session.Remove("QryClause");
                }
                LoginUser loginUser = (LoginUser)HttpContext.Current.Session["LogUserInfo"];
                CtrInterface.BindDropDown(ref ddlSearch, "NTF_A4", "NTF_A4_10", "NTF_A4_40", true, "", "NTF_A4_30=1 and NTF_A4_9994=" + loginUser.UserId + "");            
            }
            DataBindn();
        }
        /// <summary>
        /// grid 绑定
        /// </summary>
        private void DataBindn()
        {             
            NotifyBLL Bll = new NotifyBLL();
            List<MsNotifyMessage> lstMes = Bll.GetNotifyMessage(ViewState["Query"].ToString(),ViewState["Type"].ToString());
            dgMain.DataSource = lstMes;
            dgMain.DataBind();
        } 

        protected void dgMain_HtmlRowCreated(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewTableRowEventArgs e)
        {
            if (e.RowType != DevExpress.Web.ASPxGridView.GridViewRowType.Data) return;
            string sRecid = dgMain.GetRowValues(e.VisibleIndex, "id").ToString();
            string state = dgMain.GetRowValues(e.VisibleIndex, "state").ToString();
            string ucount = dgMain.GetRowValues(e.VisibleIndex, "ucount").ToString();
            HtmlAnchor lnbEdit = (HtmlAnchor)dgMain.FindRowCellTemplateControl(e.VisibleIndex, null, "lnbEdit");
            HtmlAnchor lnbDel = (HtmlAnchor)dgMain.FindRowCellTemplateControl(e.VisibleIndex, null, "lnbDel");
            DevExpress.Web.ASPxClasses.Internal.InternalWebControl ochk = (DevExpress.Web.ASPxClasses.Internal.InternalWebControl)e.Row.Cells[0].Controls[0];
            if (state == "0")
            {
                lnbDel.Disabled = true;
                ochk.Enabled = false;
                e.Row.Cells[7].Text = "<a href=\"javascript:Operate('" + sRecid + "'," + state + ",3)\">已发布</a>";
            }
            else
            {
                lnbDel.Attributes["href"] = "javascript:doDelete('" + sRecid + "')";
                e.Row.Cells[7].Text = "<a href=\"javascript:Operate('" + sRecid + "'," + state + ",3)\">未发布</a>";
            }
            lnbEdit.Attributes["href"] = "javascript:DoEdIt('" + sRecid + "')";
            e.Row.Cells[6].Text = "<a href=\"javascript:DoReply('" + sRecid + "')\">"+ucount+"</a>";
        } 
        #region Ajax Methods
        /// <summary>
        /// get budge 
        /// </summary>
        /// <param name="assetId"></param>
        /// <returns></returns>
        [global::System.Web.Services.WebMethod]
        public static string DoOperate(string sNotifyId, string Type,string state)
        {
            List<string> lstResult = new List<string>(); 
            NotifyBLL Bll = new NotifyBLL();
            lstResult = Bll.DoOperateNotify(sNotifyId, Type, state); 
            var newObj = new { message = lstResult[1], result = lstResult[0]};
            string serExpr = JavaScriptConvert.SerializeObject(newObj);
            Bll = null;
            newObj = null;
            return serExpr;
        }
        #endregion
 

        protected void lnbQuery_Click1(object sender, EventArgs e)
        {
            ViewState["Query"] = "";
            ViewState["Type"] = "2";
            NotifyBLL Bll = new NotifyBLL();
            if (ddlSearch.SelectedValue!="")
            {
                string QueryId = ddlSearch.SelectedValue;
                MsQueryClass ms = Bll.GetQueryEdit(QueryId);
                ViewState["Query"] = ms.content;                
            }
            Bll = null;
            DevExpress.Web.Data.WebDataSelection oSelect = dgMain.Selection;
            oSelect.UnselectAll();
            DataBindn();
        }
    }
}
